﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using DiscoveryLogic.Common.Utilities;

namespace DiscoveryLogic.Analytics.DataObjects
{
    public class MiscEntity:EntityBase
    {
        private string _EntityID;
        /// <summary></summary>
        public string EntityID
        {
            get
            {
                return this._EntityID;
            }
            set
            {
                this._EntityID = value;
            }
        }

        private string _EntityName;
        /// <summary></summary>
        public string EntityName
        {
            get
            {
                return this._EntityName;
            }
            set
            {
                this._EntityName = value;
            }
        }

        public MiscEntity() 
            : base(EntityType.Misc, "EntityID", "EntityName")
        {
        }

        #region Overrides of EntityBase
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xDoc"></param>
        /// <param name="entityNode"></param>
        public override void Save(ref XmlDocument xDoc, XmlNode entityNode)
        {
            XmlDataUtil.UpdateAttribute(ref xDoc, entityNode, "Score", this.Score.ToString());
            XmlDataUtil.UpdateAttribute(
                ref xDoc, entityNode, "Flag", string.IsNullOrEmpty(this.Flag) ? "" : this.Flag.ToString());

            XmlDataUtil.UpdateAttribute(ref xDoc, entityNode, "EntityID",this.EntityID);
            XmlDataUtil.UpdateAttribute(ref xDoc, entityNode,"EntityName",this.EntityName);
        }

        #endregion

        public static MiscEntity Read(XmlNode entityNode)
        {
            MiscEntity entity=new MiscEntity();
            entity.Score = double.Parse(XmlDataUtil.GetAttributeValue(entityNode, "Score", "0"));
            entity.Flag = XmlDataUtil.GetAttributeValue(entityNode, "Flag", "");
            entity.EntityID = XmlDataUtil.GetAttributeValue(entityNode, "EntityID", "");
            entity.EntityName = XmlDataUtil.GetAttributeValue(entityNode, "EntityName", "");
            return entity;
        }
    }
}
